package zz.app.yzjproject

import java.security.InvalidParameterException

/**
 * 由作者 zzq 于 2017/9/12 16:06 创建
 */
object ServerCommand {
    //hypsokinesis 后仰 forerakef 前倾
    fun standardPosture(hypsokinesisDegree:Int,forerakefDegree:Int):ByteArray{
        if(hypsokinesisDegree>0||hypsokinesisDegree<-180||forerakefDegree<0||forerakefDegree>180)
            throw InvalidParameterException("参数错误")
        return byteArrayOf(0xAA.toByte(),0x04,0x00,hypsokinesisDegree.toByte(),forerakefDegree.toByte(),0x55)
    }
    fun sampleFrequency(frequency: SampleFrequency):ByteArray{
        when(frequency){
            SampleFrequency.OncePerSecond->return byteArrayOf(0xAA.toByte(),0x03,0x01,0x01,0x55)
            SampleFrequency.OncePerTwoSeconds ->return byteArrayOf(0xAA.toByte(),0x03,0x01,0x02,0x55)
            SampleFrequency.OncePerFourSeconds ->return byteArrayOf(0xAA.toByte(),0x03,0x01,0x04,0x55)
        }
    }
    fun utcTime(year:Int,month:Int,day:Int,hour:Int,minute:Int,second:Int):ByteArray =
            byteArrayOf(0xAA.toByte(),0x06,0x02)+ Utils.valueToByteArray(Utils.convertDateTimeToUTCTimeSecond(year,month,day,hour,minute,second))+0x55
    fun queryData(type:UploadType):ByteArray{
        when(type){
            UploadType.ALL->return byteArrayOf(0xAA.toByte(),0x03,0x03,0x00,0x55)
            UploadType.ADD->return byteArrayOf(0xAA.toByte(),0x03,0x03,0x01,0x55)
        }
    }
    fun querySpace():ByteArray = byteArrayOf(0xAA.toByte(),0x03,0x04,0x00,0x55)
    fun alertRepeatTimes(time:Int)= byteArrayOf(0xAA.toByte(),0x03,0x05,time.toByte(),0x55)
    fun queryBattery()= byteArrayOf(0xAA.toByte(),0x03,0x06,0x00,0x55)
    fun alertDelayTime(time:Int)= byteArrayOf(0xAA.toByte(),0x03,0x07,time.toByte(),0x55)
    fun recordTimeSpan(h1:Int,m1:Int,s1:Int,h2:Int,m2:Int,s2:Int)=
            byteArrayOf(0xAA.toByte(),0x0A,0x08)+Utils.valueToByteArray(Utils.convertTimeToUTCTimeSecond(h1,m1,s1))+Utils.valueToByteArray(Utils.convertTimeToUTCTimeSecond(h2,m2,s2))+0x55

    fun cali(): ByteArray =byteArrayOf(0xAA.toByte(),0x03,0xF0.toByte(),0x00,0x55)
}